import os
from qagen.utils import *
from random import *
import bpy
import mathutils
from mathutils import Euler, Matrix, Vector
import math
import shutil
from PIL import Image
import numpy as np
from concurrent.futures import ThreadPoolExecutor, as_completed
from queue import Queue
import multiprocessing
from tqdm import tqdm


def recursive_select(obj):
    obj.select_set(True)
    for child in obj.children_recursive:
        child.select_set(True)

def delete_sketchfab_models(blend_file_path):
    bpy.ops.object.select_all(action='DESELECT')
    for obj in bpy.data.objects:
        if "Sketchfab_model" in obj.name:
            recursive_select(obj)
    bpy.ops.object.delete()
    bpy.ops.wm.save_mainfile(filepath=blend_file_path)

def delete_pillars(blend_file_path):
    bpy.ops.object.select_all(action='DESELECT')
    for obj in bpy.data.objects:
        if "PillarFactory" in obj.name:
            recursive_select(obj)
    bpy.ops.object.delete()
    bpy.ops.wm.save_mainfile(filepath=blend_file_path)

def delete_obj(scene_id):
    scene_path = get_scene_path(scene_id)
    bpy.ops.wm.open_mainfile(filepath=scene_path)
    delete_sketchfab_models(scene_path)

if __name__ == "__main__":

    with open('Xscene_ids.json', 'r') as f:
        scene_ids = json.load(f)
    
    for id in tqdm(scene_ids, desc="Deleting objects", unit="scene"):
        delete_obj(id)

    # num_processes = 1  # 设置最大并行数
    # num_samples = 1  # 设置要生成的样本总数
    # seed(1)
    # genqa('xxxxxxxxxxxxxxxx', '7')
    # exit(0)

